<%--
  Created by IntelliJ IDEA.
  User: zhy
  Date: 2020/8/27
  Time: 22:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>显示多个用户信息</title>
</head>
<body>
<button id="findUser" type="button">查看用户信息</button>
<table border="1" width="500" style="display: none;">
    <tr>
        <th>用户姓名</th>
        <th>密码</th>
        <th>出生日期</th>
        <th>操作</th>
    </tr>

</table>
<script type="text/javascript" src="js/jquery-1.8.3.js"></script>
<script type="text/javascript" >
    $("#findUser").click(function(){
        $.post("login1",function(data){
            for(var i=0;i<data.length;i++){
                var str="<tr contenteditable=\"true\"><td>"+data[i].id+"</td><td >"+data[i].userName+"</td><td>"+data[i].password+"</td><td>"+data[i].birthday+"</td><td><a href='javascript:void(0)' onclick=del(this,"+data[i].id+")>删除</a><a href='javascript:void(0)' onclick=modify(this,"+data[i].id+")>修改</a><td></tr>"
                $("table").append(str);
            }
            $("table").css("display","block");
        },"json")
    });
    function del(dom,id){
        alert("要删除的用户id"+id);
        $.post("delUser","id="+id,function(data){
            if(data=="true"){/*删除成功*/
                $(dom).parent().parent().remove();
            }
        })
    }
    function modify(dom,id){
        $(dom).parent().parent().attr("contenteditable",true)
        alert("要更新的用户id"+id);
        var tds=$(dom).parent().parent().children("td");
        alert(tds.length);
        alert(tds.eq(0).text());
       var str={"id":tds.eq(0).text(),"userName":tds.eq(1).text(),"password":tds.eq(2).text(),"birthday":tds.eq(3).text()}
         var jsonStr=JSON.stringify(str);
       $.ajax({
             url:"modifyUser",
             type:"post",
             data:jsonStr,
             contentType:"application/json",
             success:function(data){
                 alert("成功")
                 //$(dom).parent().parent().attr("contenteditable",false)
             }
         })
       /* $.post("modifyUser","str="+str,function(data){

            if(data=="true"){
                alert("成功")
                $(dom).parent().parent().attr("contenteditable",false)
            }
        })*/
    }
</script>
</body>
</html>
